
<!-- 索赔分析 -->
<template>
    <div>
 <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :is-select-column="false"
      :onRowSelectChange="selectChange"
      >

        <template slot="controls" slot-scope="props">
        <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
      </template>
      </FilterTable>
      <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <DealerList @close="Delearclose" @save="Delearsave"></DealerList>
      </BaseDialog>
    <BaseDialog :visible.sync="peijianVisible" :title="'祸首件选择'" width="850px" destroyOnClose  :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <peijianSelect @close="peijianClose" @save="peijianSave"></peijianSelect>
    </BaseDialog>
    <Drawer :visible.sync="visibleEdit" :title="'索赔查看'" destroyOnClose width="100%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <editForm @close="editclose" @save="editsave" :rowData="rowData"></editForm>
    </Drawer>
      </div>
</template>

<script>
import moment from "moment";
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import {getListByPage, getListForExport,exporturl} from '@/api/claim/factory/claimDemageAnalysis';
import { getClaim,getPartType } from '@/api/dictionary/index';
import peijianSelect from '@/pages/claimDemage/tools/vehicle.vue';
import editForm from './editForm.vue';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
    export  default{
        mixins: [dictionary],
        components: {
        DealerList,editForm,peijianSelect
        },
        data(){
            return{
                topFilterInit: this.topFilterInitFun(),
                fetchParams: {xhrAbort: true},
                selectDelearFlag: false,
                collapse: true,
                columns: this.creatHeader(),
                 peijianVisible: false,
                 visibleEdit: false,
                 rowData: {},
                fetchapi: getListByPage
            };

        },
  created() {
    this.fetchParams.beginSubmitAt = moment()
    .startOf('week')
    .format('YYYY-MM-DD HH:mm:ss');
    this.fetchParams.endSubmitAt = moment()
      .endOf('week')
      .format('YYYY-MM-DD HH:mm:ss');
     this.claimType()
     this.chuqi();
  },
    methods:{
    peijianTurnOn() {
      this.peijianVisible = true;
    },
        peijianClose(){
      this.peijianVisible = false;
    },
    peijianSave(obj) {
      this.topFilterInit.find(x => x.fieldName == 'partCode').initialValue = obj[0].partCode;
      this.topFilterInit.find(x => x.fieldName == 'partName').initialValue = obj[0].partName;
      this.partId = obj[0].partId;
      this.peijianVisible = false;
    },
     chuqi() {

      },
        //索赔类型
      async claimType() {
        const res2 = await getClaim();
        if (res2.resultCode == 200) {
          delete res2.data[7];
          this.topFilterInit.find(x => x.fieldName == 'cmsClaimType').initialValue = '';
          this.topFilterInit.find(x => x.fieldName == 'cmsClaimType').itemList = res2.data.map(y => ({ text: y.name, value: y.code }));
        }
      },
    //选中
    selectChange(rows) {
    //   this.selectedRows = rows;
    //   this.disableds = this.selectedRows.length <= 0;
    //   console.log(this.selectedRows);
    },
    // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000153' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // getListForExport(this.fetchParams).then(res => {
      //   exportExcelFile(res.data, '索赔分析表');
      // });
    },
    SelectDelear() {
      this.selectDelearFlag = true;
    },//关闭
    Delearclose() {
      this.selectDelearFlag = false;
    },
    //保存
    Delearsave(obj) {
      this.topFilterInit.map(x => {
        if ('ownerCode' == x.fieldName) {
          x.initialValue = obj[0].dealerCode; //维修工单号返显
        }
      })
      this.selectDelearFlag = false;

    },
    //搜索获取数据
    changeHandle(val) {
      /*刷新表格 用它*/
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort:false});
      console.log(this.fetchParams);
    },
    editclose() {
      this.visibleEdit = false;
    },
    edit(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    editsave() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'ownerCode',
          placeholder: '请输入',
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.SelectDelear()} />
              </div>
            );
          }
        },
         {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'dealerName',
          placeholder: '',
          initialValue: '',

        },

        { type: 'RANGE_DATE', label: '发票到达时间', fieldName: 'invoiceReviewTimeStar|invoiceReviewTimeEnd', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '索赔类型', fieldName: 'cmsClaimType', placeholder: '请选择', initialValue: '', itemList: [] },
        { type: 'SELECT', label: '索赔单状态', fieldName: 'claimStatus', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5513', [55131001, 55131006]) },
        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: '' },
        {
            type: 'INPUT',
            label: '车型名称',
            fieldName: 'modelName',
            disabled: false,
            placeholder: '请输入车型名称...'
          },
        {
            type: 'INPUT',
            label: '车牌号',
            fieldName: 'licenseNo',
            initialValue: '',
            disabled: false,
            placeholder: '请输入车牌号...'
          },
        {
          type: 'INPUT',
          label: '祸首件代码',
          fieldName: 'partCode',
          placeholder: '请输入',
          initialValue: '',
          unitRender: (p) => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.peijianTurnOn()} />
              </div>
            );
          },
        },
        {
            type: 'INPUT',
            label: '祸首件名称',
            fieldName: 'partName',
            initialValue: '',
            disabled: false,
            placeholder: '请输入祸首件名称...'
          },
          { type: 'RANGE_DATE', label: '索赔起始日期', fieldName: 'beginSubmitAt|endSubmitAt', placeholder: '请选择日期',
          initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ] },
        { type: 'RANGE_DATE', label: '索赔审核日期', fieldName: 'beginCheckAt|endCheckAt', placeholder: '请选择日期', initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ] },
          { type: 'RANGE_DATE', label: '结算单生成时间', fieldName: 'statementGenerationTimeStar|statementGenerationTimeEnd', placeholder: '请输入',
          initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ],
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }] },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button type="text" onClick={() => this.edit(props.row)}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '索赔类型', dataIndex: 'cmsClaimType', sorter: true },
        { title: '索赔二级分类', dataIndex: 'batchName', sorter: true },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true },
        {
              title: '服务站名称',
              dataIndex: 'dealerName',
              sorter: true
        },
        { title: '索赔单状态', dataIndex: 'claimStatus', sorter: true ,
        render: props => {
           return <span>{this.createDictText(props.row.claimStatus, '5513')}</span>;
         }},
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        { title: '工厂名称', dataIndex: 'factName', sorter: true },
        { title: '保修起始日期', dataIndex: 'repairBeginDate', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '发票到达时间', dataIndex: 'approveDate', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '车型名称', dataIndex: 'modelName', sorter: true },
        { title: '行驶里程', dataIndex: 'driveMile', sorter: true },
        { title: '故障代码', dataIndex: 'sysCode4', sorter: true },
        { title: '故障现象分析', dataIndex: 'faultName', sorter: true },
        { title: '备件金额', dataIndex: 'partAmount', sorter: true },
        { title: '维修工时金额', dataIndex: 'labourAmount', sorter: true },
        { title: '其他费用金额', dataIndex: 'addAmount', sorter: true },
        { title: '外出服务金额', dataIndex: 'helpAmount', sorter: true },
        { title: '备件管理费', dataIndex: 'partglFare', sorter: true },

        { title: '故障件运费', dataIndex: 'partFare', sorter: true },
        { title: '待批准金额', dataIndex: 'daiClaimAmount', sorter: true },
        { title: '已批准金额', dataIndex: 'claimSumAmount', sorter: true },
        { title: '授权码', dataIndex: 'authNo', sorter: true },
        { title: '外出服务单号', dataIndex: 'outNo', sorter: true },

		{ title: '维修开始日期', dataIndex: 'serviceBeginDate', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
		{ title: '维修结束日期', dataIndex: 'serviceEndDate', sorter: true,dateFormat:'yyyy-MM-dd HH:mm:ss' },
        { title: '索赔单生成日期', dataIndex: 'applyAt', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '提交日期', dataIndex: 'submitAt', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '审批日期', dataIndex: 'checkAt', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '结算单审批日期', dataIndex: 'checkAtsj', sorter: true,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '结算单生成日期', dataIndex: 'settleDate', sorter: true ,dateFormat:'yyyy-MM-dd HH:mm:ss'},
        { title: '祸首件代码', dataIndex: 'partCode', sorter: true },
        { title: '祸首件名称', dataIndex: 'partName', sorter: true },
        {
            title: '供应商代码',
            dataIndex: 'supNo',
            sorter: true
          },
        { title: '供应商名称', dataIndex: 'supName', sorter: true },
        { title: '驳回次数', dataIndex: 'channelNum', sorter: true },
        { title: '故障现象备注', dataIndex: 'faultAppear', sorter: true },
        { title: '故障原因详细描述', dataIndex: 'faultReason', sorter: true },
        { title: '检测及维修说明备注', dataIndex: 'checkRemarkjc', sorter: true },
        {
          title: '开户银行名称',
          dataIndex: 'bankName',
          sorter: true,

        },
         { title: '银行行号', dataIndex: 'yhhh', sorter: true },
         { title: '收款账号', dataIndex: 'skzh', sorter: true },
         {title: '纳税人识别号', dataIndex: 'taxpayerIdentityNumber', sorter: true },
         {title: '电话', dataIndex: 'ncvmobilen', sorter: true },
         {title: '地址', dataIndex: 'adress', sorter: true },
         // { title: '考核金额', dataIndex: 'assessAmount', sorter: true },
         // { title: '考核原因', dataIndex: 'assessReason', sorter: true },
         // { title: '发票号', dataIndex: 'invoiceNo', sorter: true },
         {title: '开票金额', dataIndex: 'invoiceSum', sorter: true},
         { title: '发票金额', dataIndex: 'invoiceMoney', sorter: true },
         {title: '税额', dataIndex: 'invoicePointAmount', sorter: true},


      ];
    },
        }
    };
 </script>
<style lang="less" scoped></style>
